package client;

import static client.domain.SandboxMainKeys.PAGE_HEIGH;
import static client.domain.SandboxMainKeys.PAGE_WIDTH;
import client.domain.ui.centerPanel.CenterPanel;
import client.domain.ui.eastPanel.EastPanel;
import client.domain.ui.northPanel.NorthPanel;
import client.domain.ui.southPanel.SouthPanel;
import client.domain.ui.westPanel.MenuTree;
import client.domain.ui.westPanel.WestPanel;
import client.internationalization.SandboxConstants;
import client.internationalization.SandboxMessages;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtext.client.widgets.tree.TreeNode;
import com.gwtext.client.widgets.tree.TreePanel;

/**
 * User: nbarrios
 * Date: Nov 5, 2009
 */
public class KaitzenGWTSandbox implements EntryPoint{

	//	Internationalization Strings
	private SandboxConstants constants = GWT.create(SandboxConstants.class);
	private SandboxMessages messages = GWT.create(SandboxMessages.class);

//	Main Panels
	private static Panel panel = new Panel();
		private Panel borderPanel = new Panel();
			private NorthPanel northPanel;
			private static WestPanel westPanel = new WestPanel();
			private static CenterPanel centerPanel;
			private static EastPanel eastPanel;
			private SouthPanel southPanel;

	//	Main Widgets
	private TreePanel treePanel = null;

	public void onModuleLoad() {
		Window.setTitle(constants.windowTitle());


		panel.setBorder(false);
		panel.setLayout(new FitLayout());
		panel.setSize(PAGE_WIDTH, PAGE_HEIGH);

		borderPanel.setLayout(new BorderLayout());


		northPanel = new NorthPanel();
		borderPanel.add(northPanel, northPanel.getNorthData());

		southPanel = new SouthPanel();
		borderPanel.add(southPanel, southPanel.getSouthData());

		eastPanel = new EastPanel();
		borderPanel.add(eastPanel, eastPanel.getEastData());

		westPanel = new WestPanel();
		this.createTreeSectionUI();
		westPanel.add(treePanel);
		borderPanel.add(westPanel, westPanel.getWestData());

		
		centerPanel = new CenterPanel();
		borderPanel.add(centerPanel, centerPanel.getCenterData());


		panel.add(borderPanel);
		new Viewport(panel);
	}

	private void createTreeSectionUI() {

		treePanel = new MenuTree();
		treePanel.setBorder(false);

		TreeNode root = new TreeNode("root");
		root.setExpanded(true);

		TreeNode node1 = new TreeNode("node1");
		node1.appendChild(new TreeNode("child1"));

		TreeNode node2 = new TreeNode("node2");
		node1.appendChild(new TreeNode("child2"));

		TreeNode node3 = new TreeNode("node3");
		node1.appendChild(new TreeNode("child3"));

		TreeNode node4 = new TreeNode("node4");
		node1.appendChild(new TreeNode("child4"));

		root.appendChild(node1);
		root.appendChild(node2);
		node2.appendChild(node3);
		node2.appendChild(node4);
		root.appendChild(new TreeNode("node5"));

		treePanel.setWidth(westPanel.getWidth());
		treePanel.setRootNode(root);

	}


//	--------------------------------------------------------------------------------------------------------------------


	//	private static Window selectTabsToAddWindow = null;
	//	Pop Ups
	//  Getters & Setters
	//	--------------------------------------------------------------------------------------------------------------------

	public static CenterPanel getCenterPanel() {
		return centerPanel;
	}

	/*public static void setCenterPanel(CenterPanel centerPanel) {
		KaitzenGWTSandbox.centerPanel = centerPanel;
	}*/

	public static EastPanel getEastPanel() {
		return eastPanel;
	}

	public static WestPanel getWestPanel() {
		return westPanel;
	}

	public static Panel getPanel() {
		return panel;
	}
}// End Class
